package com.tm.action.task;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.tm.action.BaseOperation;
import com.tm.action.DefaultAction;
import com.tm.pojo.Task;
import com.tm.service.TaskService;
import com.util.CommonResult;
import com.util.CommonResultMap;
import com.util.exception.ActionExceptioon;

public class TaskAction extends DefaultAction implements BaseOperation {
	private Task task;
	
	private TaskService taskServcie;

	@Override
	public String execute() throws ActionExceptioon {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String list() throws ActionExceptioon {
		List<Task> tasks = taskServcie.listTasks();
		request.put("tasks", tasks);
		return "list";
	}

	@Override
	public String update() throws ActionExceptioon {
		CommonResultMap map = CommonResultMap.getInstance();
		if(task != null){
			map = taskServcie.saveTask(task);
		}else{
			map.setResult(CommonResult.ERROR, "param.task.required");
		}
		if(map.succeed()){
			return "list";
		}else{
			return super.addActionError(map);
		}
	}
	
	public String goAddTask() throws ActionExceptioon{
		return "goAddTask";
	}
	

	@Override
	public String delete() throws ActionExceptioon {
		// TODO Auto-generated method stub
		return null;
	}

	public Task getTask() {
		return task;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	public TaskService getTaskServcie() {
		return taskServcie;
	}

	public void setTaskServcie(TaskService taskServcie) {
		this.taskServcie = taskServcie;
	}

	

}
